#include <iostream>
void _swap(void *p1, void *p2, int size)
{
    int i = 0;
    for (i = 0; i < size; i++)
    {
        char tmp = *((char *)p1 + i);
        *((char *)p1 + i) = *((char *)p2 + i);
        *((char *)p2 + i) = tmp;
    }
}
void _qsort(void *base, int count, int size, int (*cmp)(const void *, const void *))
{
    int i = 0;
    int j = 0;
    for (i = 0; i < count - 1; i++)
    {
        for (int j = 0; j < count - i - 1; j++)
        {
            if (cmp((char *)base + j * size, (char *)base + (j + 1) * size) > 0)
            {
                _swap((char *)base + j * size, (char *)base + (j + 1) * size, size);
            }
        }
    }
}
int int_cmp(const void *p1, const void *p2)
{
    return (*(int *)p1 - *(int *)p2);
}
void test()
{
    // 模拟qsort实现
    int arr[] = {1, 3, 5, 7, 9, 2, 4, 6, 8, 0};
    _qsort(arr, sizeof(arr) / sizeof(int), sizeof(int), int_cmp);
    for (int i = 0; i < sizeof(arr) / sizeof(int); i++)
    {
        std::cout << arr[i] << " ";
    }
    std::cout << std::endl;
}
int main()
{
    test();
    return 0;
}